const _ = require('lodash');

module.exports = function(db) {
  const collection = db.collection('statistics-daily');
  const indexes = [{ key: { date: 1 }, name: 'date_1' }];
  collection.createIndexes(indexes);

  return {
    name: 'statisticsDaily',
    updateStatisticsDaily: function(selector, update, options) {
      return collection.updateOne(selector, update, {
        upsert: true,
        ...options,
      });
    },
    findOne: function(date) {
      return collection.findOne({ date });
    },
  };
};
